

/** this class is the navigation panel for the user to navigate through the game
*/

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

/**
*
* this class is the navigation panel for the user to navigate through the game
*
 * @author Ore
 * @version $Revision: 1.0 $

*/

public class NavPanel extends JPanel {
/**
  * Field model.
  */
public Model model;

/**
  * Field view.
  */
public View view;
 
/**
  * Field x.
  */

public PlanetImg x;

/**
*
* constructor that sets up the navigation panel of the game.
*
* 
 * @param m Model
* @param v View
*/
 
public NavPanel(Model m, View v) {
setLayout(null);
model=m;
view=v;
for (int i = 0; i < model.getUniverse().getPlanetArray().length; i++) {
x = new PlanetImg(model);
x.setName(model.getUniverse().getPlanet(i).getName());
x.addMouseListener(new MyMouseListener(x, view,
model.getUniverse().getPlanet(i), model));
this.add(x);
x.setBounds(model.getUniverse().getPlanet(i).getLocation().x,
model.getUniverse().getPlanet(i).getLocation().y, 4, 4);
}
}

/**
* Method toString.
* @return String
*/
@Override
public String toString(){
return this.toString();
}

/**
* Method paintComponent.
* @param g Graphics
*/
@Override
/**
*
* sets the graphic components such as color to the navigation panel
*
* @param g
*/
public void paintComponent(Graphics g){
	final Graphics2D g2d = (Graphics2D) g;
	super.paintComponents(g2d);
	g.setColor(Color.RED);
	g.fillRect(model.getPlayer().getLocation().x,
			model.getPlayer().getLocation().y, 4, 4);
	g.setColor(Color.GREEN);
	g.drawOval(model.getPlayer().getLocation().x + 2 - 3 * model.getShip().getFuel() / 2,
			model.getPlayer().getLocation().y + 2 - 3 * model.getShip().getFuel() / 2,
			3 * model.getShip().getFuel(), 3 * model.getShip().getFuel());
	}
}
/**
*
* 
 * @author Ore
* @version $Revision: 1.0 $
*/
  class PlanetImg extends JPanel{
/**
  * Field model.
  */
public Model model;

/**
  * Constructor for PlanetImg.
  * @param model Model
  */
public PlanetImg(Model model){
this.model = model;
}

/**
* Method paintComponent.
* @param g Graphics
*/
@Override

public void paintComponent(Graphics g){
final Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLUE);
        final int width = this.getWidth() - 1;
        final int height = this.getHeight() - 1;
if(model.getPlayer().getTravel().equals(new Point(this.getX(),
this.getY())) && 
!model.getPlayer().getLocation().equals(new Point(this.getX(),
this.getY()))){
g.setColor(Color.YELLOW);
g.fillRect(0, 0, width, height);
}
if(!model.getPlayer().getLocation().equals(new Point(this.getX(),
this.getY()))){
g2d.draw(new Rectangle(0, 0, width, height));
}
}
}

/**@author Ore
 * @version 1.6
 */
class MyMouseListener implements MouseListener {
    /**
     * Field component.
     */
    public JPanel component;

    /**
     * Field v.
     */
    public View v = null;

    /**
     * Field p.
     */
    public Planet pl = null;

    /**
     * Field m.
     */
    public Model mo = null;
    
    /**
     * Method toString.
     * @return String
     */
   
    @Override
    public String toString(){
return this.toString();
}

    /**
     * Constructor for MyMouseListener.
     * @param component JPanel
     * @param v View
     * @param p Planet
     * @param m Model
     */
    public MyMouseListener(JPanel component, View v, Planet p, Model m) {
        this.component = component;
        this.v=v;
        this.pl=p;
        this.mo=m;
    }

    /**
     * Method mouseClicked.
     * @param e MouseEvent
     * @see java.awt.event.MouseListener#mouseClicked(MouseEvent)
     */
    @Override
public void mouseClicked(MouseEvent e) {
    
        v.lblPlanetName2.setText("Name: " + component.getName());
        v.lblTechLevel2.setText("Tech Level: " + pl.getTechLevel(pl.getTech()));
        v.lblResource2.setText("Resources: " + pl.getResourcesAt(pl.getResources()));
        v.repaint();
        mo.getPlayer().setTravel(component.getLocation());
        component.repaint();
    }

    /**
     * Method mouseEntered.
     * @param e MouseEvent
     * @see java.awt.event.MouseListener#mouseEntered(MouseEvent)
     */
    @Override
public void mouseEntered(MouseEvent e) {
        System.out.println("Entered: " + component.getName() + "(" + 
component.getX() + "," +
component.getY() + ")");
        
    }

    /**
     * Method mouseExited.
     * @param e MouseEvent
     * @see java.awt.event.MouseListener#mouseExited(MouseEvent)
     */
    @Override
public void mouseExited(MouseEvent e) {
        System.out.println("Exited: " + component.getName());   
    }

    /**
     * Method mousePressed.
     * @param e MouseEvent
     * @see java.awt.event.MouseListener#mousePressed(MouseEvent)
     */
    @Override
public void mousePressed(MouseEvent e) { 
    	 System.out.println("Pressed: " + component.getName()); 
    }

    /**
     * Method mouseReleased.
     * @param e MouseEvent
     * @see java.awt.event.MouseListener#mouseReleased(MouseEvent)
     */
      @Override
public void mouseReleased(MouseEvent e) { 
    	 System.out.println("Released: " + component.getName()); 
    }
}